package com.iris.dataStructures;

public class Stack<T> {
	private T[] tArray ;
	private int curPoint=-1;
	private int maxPoint=-1;
	
	public Stack(int size){
		tArray = (T[]) new Object[size];
		maxPoint=size;
	}

	public void push(T t) throws Exception{
		curPoint++;
		if(curPoint==(maxPoint-1)){
			throw new Exception("已满");
		}
		tArray[curPoint] = t;
	}
	public void remove() throws Exception{
		if(curPoint>-1){
			tArray[curPoint] = null;
			curPoint--;
		}
	}
	public T cur(){
		return tArray[curPoint];
	}

	public T pop(){
		return tArray[curPoint--];
	}
	public static void main(String[] args) {
		Stack<String> stack=new Stack<String>(5);
		try {
			stack.push("1");
			stack.push("2");
			stack.push("3");
			stack.push("4");
			System.out.println(stack.cur());
			System.out.println(stack.pop());
			System.out.println(stack.pop());
			System.out.println(stack.pop());
			stack.push("5");
			System.out.println(stack.pop());
			System.out.println(stack.pop());
			System.out.println(stack.pop());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
